<?php

namespace App\Http\Controllers\Face;

use Illuminate\Support\Facades\Log;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Validation\ValidatesRequests;


class RegisterController extends Controller
{
    use DispatchesJobs, ValidatesRequests;

    public function create() {
        return view('face.register.create');
    }

    public function store(Request $request) {
        $this->validate($request,[
            'name'    =>'required | min:3 |unique:users,name',
            'email'   =>'required | email |unique:users,email',
            'password'=>'required | min:3 | max:10 | confirmed',
        ]);

        $name     = request('name');
        $email    = request('email');
        $password = bcrypt(request('password'));

        $user = User::create(compact('name','email','password'));

        if(!empty($user)){
            return redirect('login')->with('success','注册成功!');
        }else{
            return back()->with('error','注册失败!');
        }
    }

    //protected function formatValidationErrors(Validator $validator)
    //{
    //
    //    $d = $validator->errors()->all();
    //    //dd(gettype($d));
    //    //$json_error = explode(',',);
    //    //dd(json_encode($d));
    //
    //    return $d;
    //}
}
